﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using SplendidCRM.Ext.Models;

namespace SplendidCRM.Ext.Controllers
{
    public class ExternalCallSurveyController: Controller
    {
        [HttpGet]
        public ActionResult SurveyForm()
        {
            return PartialView("SurveyForm");
        }

        [HttpGet]
        public JsonResult GetAvailablePort()
        {
            var surveyWebService = new CallSurveyWebService.Service1();
            var availablePort = surveyWebService.GetNoOfMPPActiveChannel();
            //var availablePort = 5;
            return Json(availablePort,JsonRequestBehavior.AllowGet);
        }

        [HttpPost]
        public ActionResult SaveSurvey(CallInboundModel call, CustomerInboundModel customer, bool isAgreed)
        {
            if (!ModelState.IsValid) return HttpNotFound();

            try
            {
                var currentUserId = Manager.Site.CurrentUserId;
                Db.Insert("dbo.ExternalCallSurvey", new
                                                        {
                                                            id = Guid.NewGuid(),
                                                            DateCreated = DateTime.Now,
                                                            AgentId = currentUserId,
                                                            CustomerId = customer.Id,
                                                            PhoneNumber = customer.Phone_Office,
                                                            CustomerAgree = isAgreed
                                                        });
               // throw new Exception("test show exception error in browser");

                return Json(new {Success = true});
            }
            catch(Exception exp)
            {
                return Json(new { Success = false, Error = exp.Message });
            }
        }

    }
}
